package com.wyg.observer;

/**
 * @description:    递增数字类
 * @author: WYG
 * @time: 2021/4/27 10:12
 */

public class IncrementNumberGenerator extends NumberGenerator {
    private int start;
    private int end;
    private int step;
    public IncrementNumberGenerator(int start, int end, int step) {
        this.start = start;
        this.end = end;
        this.step = step;
    }
    @Override
    public int getNumber() {
        return start;
    }

    @Override
    public void execute() {
        for (int i = start; i < end; i = i + step) {
            start = i;
            this.notifyObservers();
        }
    }

    public static void main(String[] args) {
        IncrementNumberGenerator generator = new IncrementNumberGenerator(10, 50, 5);
        DigitalObservers digitalObservers = new DigitalObservers();
        GraphObserver graphObserver = new GraphObserver();
        generator.addObserver(digitalObservers);
        generator.addObserver(graphObserver);
        generator.execute();
    }
}
